package com.pureut.system.controller;

import java.util.Arrays;
import java.util.List;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.system.domain.MesRepairManagement;
import com.pureut.system.domain.ProductRepairRecord;
import com.pureut.system.domain.vo.MesRepairManagementVo;
import com.pureut.system.service.IMesRepairManagementService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @Author: pureut
 * @Date: 2025-04-08 11:15:55
 * @Desc: MES维修管理表Controller
 */
@RestController
@RequestMapping("/system/mesRepairManagement")
public class MesRepairManagementController  extends BaseController {

    /**
     * MES维修管理表Service
     */
    @Resource
    private IMesRepairManagementService mesRepairManagementService;

    /**
     * 查询MES维修管理表列表
     * @param: params 参数列表
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("mesRepairManagement-list")
    @GetMapping("/list")
    public TableDataInfo list(MesRepairManagementVo mesRepairManagementVo) {
        startPage();
        LambdaQueryWrapper<MesRepairManagement> resultQuery = new LambdaQueryWrapper<MesRepairManagement>();
        if(ObjectUtil.isNotNull(mesRepairManagementVo.getProcessRouteCode())){
            resultQuery.like(MesRepairManagement::getProcessRouteCode, mesRepairManagementVo.getProcessRouteCode());
        }
        if(ObjectUtil.isNotNull(mesRepairManagementVo.getProcessRouteVersion())){
            resultQuery.like(MesRepairManagement::getProcessRouteVersion, mesRepairManagementVo.getProcessRouteVersion());
        }
        if(ObjectUtil.isNotNull(mesRepairManagementVo.getStartTime())&&ObjectUtil.isNotNull(mesRepairManagementVo.getEndTime())){
            resultQuery.between(MesRepairManagement::getCreateTime, mesRepairManagementVo.getStartTime(),mesRepairManagementVo.getEndTime());
        }
        return getDataTable(mesRepairManagementService.list(resultQuery));
    }


    /**
     * 获取MES维修管理表详细信息
     * @param: id MES维修管理表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("mesRepairManagement-query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(mesRepairManagementService.getById(id));
    }

    /**
     * 新增MES维修管理表
     * @param: mesRepairManagement MES维修管理表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("mesRepairManagement-add")
    @PostMapping
    public AjaxResult add(@RequestBody MesRepairManagementVo mesRepairManagementVo) {
        return toAjax(mesRepairManagementService.save(mesRepairManagementVo));
    }

    /**
     * 修改MES维修管理表
     * @param: mesRepairManagement MES维修管理表对象
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("mesRepairManagement-edit")
    @PutMapping
    public AjaxResult edit( @RequestBody MesRepairManagementVo mesRepairManagementVo) {
        return toAjax(mesRepairManagementService.updateById(mesRepairManagementVo));
    }

    /**
     * 删除MES维修管理表
     * @param: id MES维修管理表主键
     * @return: Json工具类对象
     */
    //    @SaCheckPermission("mesRepairManagement-remove")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(mesRepairManagementService.removeByIds(Arrays.asList(ids)));
    }
}
